<template>
  <div class="trade-container">
    <div class="trade-center">
      <div class="trade-top">
        <div class="title">收货地址</div>
        <div class="harvest-address">
          <span class="add-address" @click="fn">+新增收货地址</span>
        </div>
      </div>
      <div class="message-board">
        <nav>
          <h5>留言板</h5>
          <textarea
            class="textarea"
            rows="5"
            placeholder="建议留言前先与商家沟通确认"
            v-model="orderComment"
          ></textarea>
        </nav>
      </div>
      <div class="trade-middle">
        <div class="goods-list">
          <div class="goods-list-1" v-if="detailArrayList.length">
            <!-- 数据展示 -->
            <div
              class="goods-list-container"
              v-for="ordergoods in orderDetail.detailArrayList"
              :key="ordergoods.skuId"
            >
              <img class="img-1" :src="ordergoods.imgUrl" alt="订单图片" />
              <ul>
                <li>{{ ordergoods.skuName }}</li>
                <li>x{{ ordergoods.skuNum }}</li>
                <li>￥{{ ordergoods.orderPrice }}</li>
              </ul>
            </div>
            <!-- <div class="goods-list-container">
              <img class="img-1" src="./images/goods-1.webp" alt="" />
              <ul>
                <li>HUAWEI P50 Pro 8GB 雪域白 鸿蒙手机</li>
                <li>x1</li>
                <li>￥5858.00</li>
              </ul>
            </div> -->
          </div>
          <div class="no-data" v-else>
            <div class="nodata">暂无数据,请添加</div>
          </div>

          <div class="goods-list-right">
            <div class="goods-list-right-top">
              <h1>商品由<em>华为商城</em>选择合作快递</h1>
              <p><span></span> 标准配送</p>
            </div>

            <div class="order-price-detail">
              <ul class="total-money">
                <li>
                  <span class="span-w">商品总金额:</span>
                  <span>￥{{ orderDetail.originalTotalAmount }}</span>
                </li>
                <li>
                  <span class="span-w">商品数量:</span>
                  <span>{{ orderDetail.totalNum }}</span>
                </li>
                <li>
                  <span class="span-w">运费:</span>
                  <span>￥0.00</span>
                </li>
                <li>
                  <span class="span-w"> 优惠金额:</span>
                  <span>
                    - ¥
                    {{
                      orderDetail.originalTotalAmount - orderDetail.totalAmount
                    }}</span
                  >
                </li>

                <li>
                  <span class="span-w">决算金额:</span>
                  <span class="span-strong"
                    >￥{{ orderDetail.totalAmount }}</span
                  >
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
      <div class="trade-footer">
        <div class="trade-submit">
          <p>
            应付金额: <span>￥{{ orderDetail.totalAmount }}</span>
          </p>
          <nav>
            <span>无收货地址不可下单，<a href="#">点击填充</a> </span>
          </nav>
          <button @click="submitOrder">提交订单</button>
        </div>
      </div>
    </div>
    <el-dialog title="Tips" :visible.sync="dialogVisible" width="30%">
      <span>This is a message</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >Confirm</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { getTradeApi, submitOrderApi } from "@/api/tradeApi/index";
export default {
  name: "XTrade",
  data() {
    return {
      dialogVisible: false, //弹框
      orderDetail: {},
      orderComment: "",
      detailArrayList: [],
    };
  },
  methods: {
    fn() {
      this.dialogVisible = true;
    },
    async submitOrder() {
      const { tradeNo, detailArrayList } = this.orderDetail;
      const orderId = await submitOrderApi({
        tradeNo,
        consignee: "嘿咻",
        consigneeTel: "13989898939",
        deliveryAddress: "西湖湖底",
        paymentWay: "ONLINE",
        orderComment: this.orderComment,
        orderDetailList: detailArrayList,
      });
      console.log("订单提交的返回值", orderId);

      this.$router.push(`/pay?orderId=${orderId}`);
    },
  },
  async mounted() {
    const result = await getTradeApi();
    this.orderDetail = result;
    this.detailArrayList = this.orderDetail.detailArrayList;
  },
};
</script>

<script lang="ts" setup></script>

<style lang="less" scoped>
.trade-container {
  background-color: #f5f5f5;
  padding-top: 20px;
  overflow: hidden;
  .trade-center {
    width: 1200px;
    margin: 0 auto;
    .trade-top {
      height: 209px;
      padding-left: 60px;
      background-color: #fff;
      .title {
        padding-top: 32px;
        font-size: 18px;
        height: 30px;
        margin-bottom: 30px;
        color: #3a3a3a;
        line-height: 30px;
      }
      .harvest-address {
        width: 762px;
        height: 80px;
        border: 1px solid #eaeaea;
        .add-address {
          width: 140px;
          display: block;
          margin: 0 auto;
          line-height: 80px;
          color: #3a3a3a;
        }
      }
    }
    .trade-middle {
      margin-top: 20px;
      background-color: #fff;
      border: 1px solid #eaeaea;
      .goods-list {
        display: flex;
        .goods-list-1 {
          width: 800px;
          display: flex;
          align-items: center;
          .goods-list-container {
            width: 760px;
            padding: 20px;
            display: flex;
            .img-1 {
              width: 100px;
              height: 100px;
            }
            ul {
              display: flex;
              width: 650px;
              justify-content: space-between;
              margin-top: 20px;
            }
          }
        }
        .goods-list-right {
          width: 400px;
          background-color: #f6f6f6;
          border-left: 1px solid #3a3a3a;
          padding: 0 20px;
          .goods-list-right-top {
            padding-top: 28px;
            border-bottom: 1px solid #eaeaea;
            h1 {
              font-size: 18px;
              em {
                color: red;
              }
            }
            p {
              margin-top: 11px;
              padding-bottom: 20px;
            }
          }
          .order-price-detail {
            width: 100%;
            height: 100%;
            // position: relative;
            .total-money {
              // position: absolute;
              // bottom: 131px;
              // right: 0;
              li {
                width: 257px;
                display: flex;
                font-size: 14px;
                color: #3a3a3a;
                margin: 8px 0;
                justify-content: space-between;
                .span-w {
                  text-align: right;
                  width: 151px;
                }
                .span-strong {
                  font-weight: normal;
                  color: #ca141d;
                  font-size: 22px;
                }
              }
            }
          }
        }
      }
    }
    .trade-footer {
      margin: 30px 0;
      background-color: #fff;
      padding: 40px 40px 16px;
      overflow: hidden;
      .trade-submit {
        float: right;
        p {
          height: 74px;
          font-size: 18px;
          span {
            text-decoration: dashed;
            font-size: 30px;
            color: #ca141d;
          }
        }
        nav {
          background-color: #fef2f2;
          padding: 20px;
          border: 1px solid #ca141d;
          span {
            font-size: 12px;
            color: #ca141d;
          }
        }
        button {
          float: right;
          margin-top: 20px;
          text-align: center;
          background: #ca141d;
          color: #fff;
          width: 172px;
          height: 46px;
          line-height: 46px;
          font-size: 18px;
          border-radius: 2px;
        }
      }
    }
    .message-board {
      margin: 30px 0;
      background-color: #fff;
      padding: 40px 40px 16px;
      nav {
        textarea {
          margin-top: 10px;
          width: 100%;
        }
      }
    }
  }
}
.no-data {
  width: 800px;
  height: 278px;
  position: relative;
  .nodata {
    margin: 0 auto;
    width: 200px;
    height: 200px;
    line-height: 200px;
    text-align: center;
    border-radius: 50%;
    background-color: #e0e0e0;
    position: absolute;
    top: 14%;
    left: 286px;
    font-size: 20px;
    color: white;
  }
}
</style>